<script setup>
import { defineProps } from 'vue'
import { formatISODate } from '@/utils/date'
import { useRouter } from 'uniapp-router-next'

const router = useRouter()
const props = defineProps({
  project: {
    type: Object,
    required: true,
  },
})

const handleToInfo = () => {
  router.navigateTo({
    path: '/pages/projectInfoPage/index',
    //参数
    query: {
      project_id: props.project?.projectDetail?.project_id,
    },
  })
}
const handleReason = () => {
  uni.showModal({
    title: '审批留言',
    content: props.project?.reason ?? '暂无留言',
    showCancel: true,
  })
}
</script>

<template>
  <view class="card">
    <view class="cardleft">
      <img class="lmg" src="../../../static/projectImg.png" alt="" />
    </view>
    <view class="cardright">
      <div class="title">
        <span>{{ props.project?.projectDetail.title }}</span>
        <up-icon
          name="arrow-right"
          size="20"
          color="#b4b5b7"
          class="icon"
          :style="{ marginRight: 15 + 'px' }"
          @click="handleToInfo"
        ></up-icon>
      </div>
      <span class="date">
        <up-badge :is-dot="true" type="success"></up-badge>&nbsp;&nbsp;
        <p>{{ formatISODate(props.project?.projectDetail?.start_time) }}</p>
      </span>
      <span class="date">
        <up-badge :is-dot="true" type="error"></up-badge>&nbsp;&nbsp;
        <p>{{ formatISODate(props.project?.projectDetail?.over_time) }}</p>
      </span>
      <div class="wrapper">
        <text class="link" @click="handleReason"
          >审批状态：{{
            props?.project.status === 1 ? '审批通过' : props?.project.status === 2 ? '审批驳回' : '等待审批'
          }}</text
        >
      </div>
    </view>
  </view>
</template>

<style scoped lang="scss">
.card {
  background-color: #fff;
  display: flex;
  width: 95%;
  height: 130px;
  flex-direction: row;
  border-radius: 10px;
  justify-content: center;
  margin: 10px;
  .cardleft {
    flex-grow: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    ::v-deep.lmg {
      width: 110px;
      height: 110px;
      border-radius: 15px;
    }
  }
  .cardright {
    height: 120px;
    flex-grow: 7;
    display: flex;
    flex-direction: column;
    ::v-deep.title {
      flex-grow: 3;
      width: 90%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: rgb(28, 40, 62);
    }
    .icon {
      margin-right: 15px;
    }
    ::v-deep.date {
      flex-grow: 1;
      color: #d1c5c5;
    }
    .wrapper {
      height: 30px;
      width: 70%;
      margin-right: 10px;
      border-radius: 15px;
      background-color: rgb(239, 240, 244);
      display: flex;
      justify-content: start;
      align-items: center;
      ::v-deep.link {
        text-decoration: none;
        color: rgb(122, 128, 142);
        font-size: 12px;
        overflow-wrap: break-word; /* 允许长单词换行 */
        word-wrap: break-word; /* 支持旧版浏览器 */
        white-space: normal; /* 允许换行 */
        text-align: start;
        padding-left: 15px;
      }
    }

    .date {
      display: flex;
      align-items: center;
    }
  }
}
</style>
